<?php
namespace Login\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        //print_r($_POST);
        //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>[ 您现在访问的是Home模块的Index控制器 ]</div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
        $this->display();
    }

    public function VerifyLogin(){
        $mobile = I('post.mobile');
        $pass   = I('post.pass');



        if($mobile == null){
            exit(json_encode(array('code'=>101,'message'=>'请输入手机号！')));
        }elseif($pass == null){
            exit(json_encode(array('code'=>102,'message'=>'请输入密码！')));
        }else{
            //数据库检查逻辑结构,成功返回200
            $user = M('user');
            $ret  = $user->where("mobile='$mobile'")->find();

            if($ret == null){
                exit(json_encode(array('code'=>103,'message'=>'用户不存在！')));
            }elseif($ret['pass'] == $pass){
                session('uid',$ret['uid']);
                session('name',$ret['name']);
                session('mobile',$ret['mobile']);

                exit(json_encode(array('code'=>200)));
            }elseif ($ret['pass'] != $pass){
                exit(json_encode(array('code'=>104,'message'=>'密码不正确！')));
            }else{
                exit(json_encode(array('code'=>105,'message'=>'未知错误！登陆失败！')));
            }

        }

    }

    public function LoginOut(){
        session('uid',null);
        session('name',null);
        session('mobile',null);
        $this->success('退出成功','Home',3);
    }
}